package controllers;

import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import dominio.*;

public class LoginValidador implements Validator {

    @SuppressWarnings("unchecked")
    @Override
    public boolean supports(Class clazz) {
        return Persona.class.equals(clazz);
    }

    @Override
    public void validate(Object obj, Errors errors) {
        Persona pers = (Persona) obj;

        if (!StringUtils.hasLength(pers.getUsuario())) {
            errors.rejectValue("usuario", "required", "Usuario es obligatorio");
        }

        if (!StringUtils.hasLength(pers.getClave())) {
            errors.rejectValue("clave", "required", "Password es obligatoria");
        }
    }
}
